import { Component, ViewChild, ElementRef, Input } from '@angular/core'
import { IonicPage, NavController, NavParams, Slides } from 'ionic-angular'
import { HttpServicesProvider } from '../../../providers/http-services/http-services'
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner'
import { ScanPage } from '../../scan/scan'
import { MeseaminspectionworkdetailitemsPage } from '../meseaminspectionworkdetailitems/meseaminspectionworkdetailitems'

declare let echarts //设置echarts全局对象
declare let Swiper
@IonicPage()
@Component({
  selector: 'page-meseaminspectionworkdetail',
  templateUrl: 'meseaminspectionworkdetail.html'
})
export class MeseaminspectionworkdetailPage {
  finditeminformation: any[]
  buttons: any[]
  inspectionWorkNum: string
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public httpService: HttpServicesProvider,
    public element: ElementRef,
    private qrScanner: QRScanner
  ) {}

  ionViewDidLoad(navParams: NavParams) {
    this.inspectionWorkNum = this.navParams.get('item').inspectionWorkNum
    this.getList()
  }
  circleClick(x) {
    let data = {
      inspectionWorkNum: x.inspectionWorkNum,
      inspectionPathNum: x.inspectionPathNum,
      inspectionPositionNum: x.inspectionPositionNum,
      inspectionStatus: x.inspectionStatus
    }
    if (x.inspectionStatus != '1001') {
      this.positionData(data)
    } else {
      this.navCtrl.push(ScanPage, { x, callback: this.myCallbackFunction })
    }
  }
  // 用于扫码后pop的回调
  myCallbackFunction = params => {
    return new Promise((resolve, reject) => {
      if (typeof params != 'undefined') {
        resolve('ok')
        this.positionData(params)
      } else {
        reject(Error('error'))
      }
    })
  }
  // 巡检点位数据请求
  positionData(params) {
    this.httpService.requestDataPost(
      'app/inspectionwork/finditeminformation',
      params,
      {},
      (status, datas) => {
        if (status) {
          this.getList()
          this.finditeminformation = datas
        }
      }
    )
  }
  // 巡检点位详细
  buttonClick(x) {
    this.navCtrl.push(MeseaminspectionworkdetailitemsPage, { x })
  }
  // 初始化圆圈按钮
  getList() {
    this.httpService.requestDataPost(
      'app/inspectionwork/findpointlocation',
      { inspectionWorkNum: this.inspectionWorkNum },
      {},
      (status, datas) => {
        if (status) {
          this.buttons = datas
        }
      }
    )
  }
}
